import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

public class Test {
    public static void main(String[] args) throws Exception{
//        DataSource ds = new ComboPooledDataSource();//使用c3p0的数据源
//        DataSource ds = new ComboPooledDataSource();
//        Connection con = ds.getConnection();
//        PreparedStatement ps = con.prepareStatement("select g.id,g.name,g.price,t.name typename from recommend r,goods g,type t where r.type = 2 and r.goods_id=g.id and g.type_id=t.id;");
//        ResultSet rs = ps.executeQuery();
//        while(rs.next()){
//            System.out.println(rs.getString("name"));
//        }
//        rs.close();
//        ps.close();
//        con.close();

        DataSource ds = new ComboPooledDataSource();
        QueryRunner r = new QueryRunner(ds);
        String sql = "select * from goods";
        List<Object[]> list = r.query(sql,new ArrayListHandler());
        for (Object[] objs : list){
            for (Object o : objs){
                System.out.println(o+" ");
            }
            System.out.println();
        }
    }
}
